#include "StdAfx.h"
#include "BoardStack.h"


CBoardStack::CBoardStack(int lineCount):m_LineCount(lineCount)
{
	m_ElementCount = 0;
}


void CBoardStack::Init(void)
{
	for (int i=0; i<BOARD_STACK_LENGTH; i++) {
		m_pNodeArray[i] = new CGoBoardWithCommonProcess(m_LineCount);
		m_pNodeArray[i]->Init();
	}
}


CBoardStack::~CBoardStack(void)
{
	for (int i=0; i<BOARD_STACK_LENGTH; i++) {
		delete m_pNodeArray[i];
	}
}


void CBoardStack::GetTop(CGoBoardWithCommonProcess *pNode) const
{
	TRACE("stack length = %d\n", m_ElementCount);
	ASSERT(m_ElementCount > 0);
	pNode->Copy(*m_pNodeArray[m_ElementCount - 1]);
}


void CBoardStack::Push(const CGoBoardWithCommonProcess &node)
{
	ASSERT(m_ElementCount < BOARD_STACK_LENGTH);
	m_pNodeArray[m_ElementCount++]->Copy(node);
}


void CBoardStack::Pop(void)
{
	ASSERT(m_ElementCount > 0);
	m_ElementCount--;
}